extends CharacterBody2D

var bullet_owner

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity") 

func _physics_process(delta):
	# Add the gravity.
	if not is_on_floor():
		velocity.y += gravity * delta
	
	if is_on_floor():
		self.velocity.y = 0
	
	var collision_info = move_and_collide(velocity * delta)
	if collision_info:
		velocity = (velocity*0.8).bounce(collision_info.get_normal())
	

func _on_area_2d_body_entered(body):
	if self.velocity.length() <= 50:
			if body.is_in_group("picker"):
				if body.pick():
					self.queue_free()
			return
	if body.is_in_group("hittable") and not (body == bullet_owner):
		
		body.hitted()
	
		
